home *** CD-ROM | disk | FTP | other *** search
- <HTML>
-
- <HEAD>
-
- <TITLE>moving layer object</TITLE>
-
- </HEAD>
-
-
-
- <SCRIPT LANGUAGE="JavaScript">
-
- var L=new layerTool();
-
- function layerTool()
-
- {
-
- if (navigator.appName=="Netscape")
-
- this.layerProp=navProp;
-
- else
-
- this.layerProp=exProp;
-
- }
-
- function exProp()
-
- {
-
- return document.all[arguments[arguments.length-1]].style;
-
- }
-
- function navProp()
-
- {
-
- retVal="";
-
- for (var x=0;x<arguments.length;x++)
-
- {
-
- retVal+="document.layers[\'"+arguments[x]+"\']";
-
- if (x!=arguments.length-1)
-
- retVal+=".";
-
- }
-
- return eval(retVal);
-
- }
-
- function Point(X,Y)
-
- {
-
- this.x=X;
-
- this.y=Y;
-
- }
-
- function layerObject(layerID,pos,vel,z)
-
- {
-
- // properties
-
- this.layerID=layerID;
-
- this.position=pos;
-
- this.velocity=vel;
-
- this.depth=z;
-
- this.visibility="visible";
-
- // methods
-
- this.show=showLayer;
-
- this.hide=hideLayer;
-
- this.setPosition=setPosition;
-
- this.draw=drawLayer;
-
- this.update=layerUpdate;
-
- this.show();
-
- }
-
- function setZorder(z)
-
- {
-
- this.depth=z;
-
- }
-
- function showLayer()
-
- {
-
- L.layerProp(this.layerID).visibility="visible";
-
- }
-
- function hideLayer()
-
- {
-
- L.layerProp(this.layerID).visibility="hidden";
-
- }
-
- function drawLayer()
-
- {
-
- L.layerProp(this.layerID).zIndex=this.depth;
-
- L.layerProp(this.layerID).left=(this.position).x;
-
- L.layerProp(this.layerID).top=(this.position).y;
-
- }
-
- function setPosition(pos)
-
- {
-
- this.position=pos;
-
- }
-
- function layerUpdate()
-
- {
-
- var newPos=new Point(this.position.x+this.velocity.x,
-
- this.position.y+this.velocity.y);
-
- this.setPosition(newPos);
-
- }
-
- function init()
-
- {
-
- mySprite=new layerObject("sprite1",new Point(0,0),new Point(5,5),1);
-
- cycle();
-
- }
-
- function cycle()
-
- {
-
- mySprite.update();
-
- mySprite.draw();
-
- setTimeout("cycle()",30);
-
- }
-
- </SCRIPT>
-
- <STYLE>
-
-
-
- #sprite1{
-
- POSITION: absolute;
-
- VISIBILITY: hidden
-
- }
-
-
-
- </STYLE>
-
- <BODY BGCOLOR="#000000" onLoad="init()">
-
- <DIV ID="sprite1">
-
- <IMG SRC="rock.gif">
-
- </DIV>
-
- </BODY>
-
- </HTML>
-
-